package edu.sctu.xuping.month06.subwaysystem;

import java.util.HashMap;

public class CardHandle {
    private HashMap<String, Integer> map;

    /**
     * 计算经过了多少站
     *
     * @param map
     */
    public CardHandle(HashMap<String, Integer> map) {
        this.map = map;
    }

    public int getPassStation(String startstation, String endstation) {
        int count = 0;
        if (map.get(startstation) > map.get(endstation)) {
            count = map.get(startstation) - map.get(endstation);
        } else {
            count = map.get(endstation) - map.get(startstation);
        }
        return count;
    }

    /**
     * 计算乘坐地铁需花多少钱
     *
     * @param startstation
     * @param endstation
     * @return
     */
    public int getPrice(String startstation, String endstation) {
        int price = 2;
        if (getPassStation(startstation, endstation) < 3) {
            price = 2;
        } else if (getPassStation(startstation, endstation) >= 3 && getPassStation(startstation, endstation) < 6) {
            price = 4;
        } else if (getPassStation(startstation, endstation) >= 6 && getPassStation(startstation, endstation) < 8) {
            price = 6;
        } else if (getPassStation(startstation, endstation) > 8)
            price = 8;
        return price;
    }

    /**
     * 充钱
     *
     * @param balance
     * @param people
     */
    public int reCharge(int balance, PeopleInformation people) {
        int leftmoney = balance + people.getPice();
        System.out.println("余额为" + leftmoney);
        return leftmoney;
    }

}